package com.xbongbong.paas.controller.mobile;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.serializer.SerializerFeature;
import com.xbongbong.crm.perform.query.list.impl.CompetitorListServiceImpl;
import com.xbongbong.crm.perform.query.list.impl.ContactListServiceImpl;
import com.xbongbong.crm.perform.query.list.impl.ContractListServiceImpl;
import com.xbongbong.crm.perform.query.list.impl.CustomerListServiceImpl;
import com.xbongbong.crm.perform.query.list.impl.MarketActivityListServiceImpl;
import com.xbongbong.crm.perform.query.list.impl.OpportunityListServiceImpl;
import com.xbongbong.crm.service.executor.query.DingtalkPublicPoolListQry;
import com.xbongbong.executor.query.CommonDingtalkListQry;
import com.xbongbong.paas.domain.entity.ext.PaasFormDataEntityExt;
import com.xbongbong.paas.domain.entity.ext.PaasFormEntityExt;
import com.xbongbong.paas.model.PaasFormModel;
import com.xbongbong.paas.pojo.ButtonPojo;
import com.xbongbong.paas.pojo.dto.FormDataGetDTO;
import com.xbongbong.paas.pojo.dto.FormDataListDTO;
import com.xbongbong.paas.pojo.dto.GroupApplyScoreGetDTO;
import com.xbongbong.paas.pojo.vo.PaasFormDataEsListVO;
import com.xbongbong.paas.service.TransferBackRuleSeniorService;
import com.xbongbong.paas.toolbox.exception.XbbException;
import com.xbongbong.paas.toolbox.thread.TransmittableThreadLocalUtil;
import com.xbongbong.paas.toolbox.util.BeanUtil;
import com.xbongbong.paas.toolbox.util.CloneUtil;
import com.xbongbong.paas.toolbox.wrap.BaseDTO;
import com.xbongbong.paas.toolbox.wrap.BaseVO;
import com.xbongbong.paas.toolbox.wrap.XbbResponse;
import com.xbongbong.pro.applist.pojo.vo.ListAppExtVO;
import com.xbongbong.pro.applist.pojo.vo.ListAppVO;
import com.xbongbong.pro.applist.pojo.vo.WaitNumVO;
import com.xbongbong.pro.common.pojo.CheckRepeatToolPojo;
import com.xbongbong.pro.common.pojo.dto.CustomerCheckRepeatDTO;
import com.xbongbong.pro.common.pojo.dto.MobileCheckRepeatToolDTO;
import com.xbongbong.pro.common.pojo.vo.CheckRepeatToolVO;
import com.xbongbong.pro.common.pojo.vo.DimensionViewPoJo;
import com.xbongbong.pro.constant.XbbProConstant;
import com.xbongbong.pro.detailtab.dto.DetailTabDataGetDTO;
import com.xbongbong.pro.detailtab.dto.OrderOnPinDTO;
import com.xbongbong.pro.detailtab.dto.UpdateMyTeamDTO;
import com.xbongbong.pro.enums.DistributorMarkEnum;
import com.xbongbong.pro.enums.SaasMarkEnum;
import com.xbongbong.pro.enums.errorcodes.SystemErrorCodeEnum;
import com.xbongbong.pro.enums.permission.enums.AddProPermissionAliasEnum;
import com.xbongbong.pro.enums.permission.enums.ProPermissionAliasEnum;
import com.xbongbong.pro.knowledge.base.pojo.dto.KnowledgeListDTO;
import com.xbongbong.pro.knowledge.base.pojo.vo.KnowledgeBaseListVO;
import com.xbongbong.pro.marketManage.pojo.dto.RelationSaleClueListDTO;
import com.xbongbong.pro.marketManage.pojo.vo.RelationSaleClueListVO;
import com.xbongbong.pro.paymenttask.pojo.dto.PaymentTaskGetDTO;
import com.xbongbong.pro.product.pojo.dto.ProductStockWarningListDTO;
import com.xbongbong.pro.product.pojo.vo.ProductStockWarningListVO;
import com.xbongbong.pro.publicgroup.pojo.vo.PublicGroupScreenVO;
import com.xbongbong.pro.publicgroup.pojo.vo.PublicGroupSeniorListVO;
import com.xbongbong.pro.weblist.pojo.WorkReportPojo;
import com.xbongbong.pro.weblist.pojo.dto.CommunicatePlanDTO;
import com.xbongbong.pro.weblist.pojo.dto.NearCustomerDTO;
import com.xbongbong.pro.weblist.pojo.dto.WorkReportListDTO;
import com.xbongbong.pro.weblist.pojo.vo.CommunicateVO;
import com.xbongbong.pro.weblist.pojo.vo.CustomerPlanVO;
import com.xbongbong.pro.weblist.pojo.vo.WaitPurchaseDetailVO;
import com.xbongbong.pro.weblist.pojo.vo.WaitPurchaseProductVO;
import com.xbongbong.pro.weblist.pojo.vo.WorkReportVO;
import com.xbongbong.pro.workorder.pojo.vo.WorkOrderDataEsListVO;
import com.xbongbong.saas.domain.entity.ext.WorkOrderEntityExt;
import com.xbongbong.saas.enums.ListTopButtonEnum;
import com.xbongbong.saas.enums.SaasButtonEnum;
import com.xbongbong.saas.enums.XbbRefTypeEnum;
import com.xbongbong.saas.help.SaasListHelp;
import com.xbongbong.saas.service.ClueService;
import com.xbongbong.saas.service.CommonService;
import com.xbongbong.saas.service.CommunicatePlanService;
import com.xbongbong.saas.service.ContractService;
import com.xbongbong.saas.service.CreditFixedLimitService;
import com.xbongbong.saas.service.CreditLimitService;
import com.xbongbong.saas.service.CreditTemporaryLimitService;
import com.xbongbong.saas.service.CustomerService;
import com.xbongbong.saas.service.DistributorAccountService;
import com.xbongbong.saas.service.DistributorCommunicateService;
import com.xbongbong.saas.service.DistributorContactService;
import com.xbongbong.saas.service.DistributorManageService;
import com.xbongbong.saas.service.InvoiceService;
import com.xbongbong.saas.service.KnowledgeBaseService;
import com.xbongbong.saas.service.KnowledgeDataService;
import com.xbongbong.saas.service.MobileDetailService;
import com.xbongbong.saas.service.OnlinePaymentFlowService;
import com.xbongbong.saas.service.OrderService;
import com.xbongbong.saas.service.OtherExpenseService;
import com.xbongbong.saas.service.OtherIncomeService;
import com.xbongbong.saas.service.PayBalanceService;
import com.xbongbong.saas.service.PayPlanSheetService;
import com.xbongbong.saas.service.PaymentBalanceService;
import com.xbongbong.saas.service.PaymentService;
import com.xbongbong.saas.service.PaymentSheetService;
import com.xbongbong.saas.service.PaymentTaskService;
import com.xbongbong.saas.service.PurchaseInvoiceService;
import com.xbongbong.saas.service.SaasDetailTabService;
import com.xbongbong.saas.service.SaasListService;
import com.xbongbong.saas.service.WorkOrderFormDataService;
import com.xbongbong.saas.service.WorkOrderService;
import com.xbongbong.saas.service.WorkReportService;
import org.springframework.http.MediaType;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.Set;

/**
 * @author long.rao
 * @version v1.0
 * @date 2019/3/6 14:38
 * @since v1.0
 */
@RestController
@RequestMapping(value = XbbProConstant.API_ROOT_PREFIX + "/mobile/list")
public class MobileSaasListController {

    @Resource
    private SaasListService saasListService;
    @Resource
    private CustomerService customerService;
    @Resource
    private OrderService orderService;
    @Resource
    private WorkReportService workReportService;
    @Resource
    private PaymentService paymentService;
    @Resource
    private InvoiceService invoiceService;
    @Resource
    private SaasDetailTabService saasDetailTabService;
    @Resource
    private PaasFormModel paasFormModel;
    @Resource
    private WorkOrderFormDataService workOrderFormDataService;
    @Resource
    private WorkOrderService workOrderService;
    @Resource
    private SaasListHelp saasListHelp;
    @Resource
    private CommunicatePlanService communicatePlanService;
    @Resource
    private PaymentBalanceService paymentBalanceService;
    @Resource
    private PaymentSheetService paymentSheetService;
    @Resource
    private PayBalanceService payBalanceService;
    @Resource
    private PayPlanSheetService payPlanSheetService;
    @Resource
    private CreditLimitService creditLimitService;
    @Resource
    private CreditTemporaryLimitService creditTemporaryLimitService;
    @Resource
    private CreditFixedLimitService creditFixedLimitService;
    @Resource
    private PurchaseInvoiceService purchaseInvoiceService;
    @Resource
    private OtherIncomeService otherIncomeService;
    @Resource
    private OtherExpenseService otherExpenseService;
    @Resource
    private ClueService clueService;
    @Resource
    private MobileDetailService mobileDetailService;
    @Resource
    private PaymentTaskService paymentTaskService;
    @Resource
    private DistributorCommunicateService distributorCommunicateService;
    @Resource
    private DistributorManageService distributorManageService;
    @Resource
    private DistributorContactService distributorContactService;
    @Resource
    private DistributorAccountService distributorAccountService;
    @Resource
    private OnlinePaymentFlowService onlinePaymentFlowService;
    @Resource
    private CustomerListServiceImpl customerListService;
    @Resource
    private ContractListServiceImpl contractListService;
    @Resource
    private CommonService commonService;
    @Resource
    private ContactListServiceImpl contactListService;
    @Resource
    private OpportunityListServiceImpl opportunityListService;

    @Resource
    private MarketActivityListServiceImpl marketActivityListService;
    @Resource
    private CommonDingtalkListQry commonDingtalkListQry;
    @Resource
    private DingtalkPublicPoolListQry dingtalkPublicPoolListQry;
    @Resource
    private ContractService contractService;
    @Resource
    private CompetitorListServiceImpl competitorListService;


    @Resource
    private TransferBackRuleSeniorService transferBackRuleSeniorService;
    @Resource
    private KnowledgeBaseService knowledgeBaseService;
    @Resource
    private KnowledgeDataService knowledgeDataService;

    /**
     * 获取客户数据列表
     * @param formDataListDTO
     * @param br
     * @return
     */
    @RequestMapping(value = "/customer", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String customerList(@RequestBody @Valid FormDataListDTO formDataListDTO, BindingResult br) {
        XbbResponse<ListAppVO> response;
        if (br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                TransmittableThreadLocalUtil.setValue(formDataListDTO.getSaasMark(), formDataListDTO.getBusinessType(), formDataListDTO.getMenuId(), formDataListDTO.getDistributorMark());
//                PaasFormDataEsListVO paasFormDataEsListVO = saasListService.customerList(formDataListDTO);
//                List<PaasFormDataEntityExt> esEntities = paasFormDataEsListVO.getPaasFormDataESList();
//                Integer totalCount = paasFormDataEsListVO.getPageHelper().getRowsCount();
//                ListAppVO listAppVO = new ListAppVO();
//                if (totalCount != null && totalCount != 0) {
//                    listAppVO = customerService.formatCustomerAppList(formDataListDTO, esEntities, totalCount);
//                } else {
//                    listAppVO.setList(new ArrayList<>());
//                    listAppVO.setTotalCount(0);
//                }
//                listAppVO.setAddPermission(saasListService.getAppListAddPermission(paasFormDataEsListVO));
                ListAppVO listAppVO = customerListService.dingtalkList(formDataListDTO);
                response = new XbbResponse<>(listAppVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }
        return JSON.toJSONString(response, SerializerFeature.DisableCircularReferenceDetect);
    }

    /**
     * 获取全部线索数据列表
     * @param formDataListDTO
     * @param br
     * @return
     */
    @RequestMapping(value = "/clue", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String clueList(@RequestBody @Valid FormDataListDTO formDataListDTO, BindingResult br) {
        XbbResponse<ListAppVO> response;
        if (br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                TransmittableThreadLocalUtil.setValue(formDataListDTO.getSaasMark(), formDataListDTO.getBusinessType(), formDataListDTO.getMenuId(), DistributorMarkEnum.OTHER.getCode());
//                PaasFormDataEsListVO paasFormDataEsListVO = saasListService.clueList(formDataListDTO);
//                List<PaasFormDataEntityExt> esEntities = paasFormDataEsListVO.getPaasFormDataESList();
//                Integer totalCount = paasFormDataEsListVO.getPageHelper().getRowsCount();
//                ListAppVO listAppVO = new ListAppVO();
//                if (totalCount != null && totalCount != 0) {
//                    listAppVO = clueService.formatClueAppList(formDataListDTO, esEntities, totalCount);
//                } else {
//                    listAppVO.setList(new ArrayList<>());
//                    listAppVO.setTotalCount(0);
//                }
//                listAppVO.setAddPermission(saasListService.getAppListAddPermission(paasFormDataEsListVO));
                ListAppVO listAppVO = commonDingtalkListQry.dingtalkExecute(formDataListDTO);
                response = new XbbResponse<>(listAppVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }
        return JSON.toJSONString(response, SerializerFeature.DisableCircularReferenceDetect);
    }

    /**
     * 线索回收站
     * @param formDataListDTO
     * @param br
     * @return
     */
    @RequestMapping(value = "/delClue", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String delClueList(@RequestBody @Valid FormDataListDTO formDataListDTO, BindingResult br) {
        XbbResponse<PaasFormDataEsListVO> response;
        if (br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                // 手机端没有线索回收站
                TransmittableThreadLocalUtil.setValue(formDataListDTO.getSaasMark(), formDataListDTO.getBusinessType(), formDataListDTO.getMenuId(), DistributorMarkEnum.OTHER.getCode());
                PaasFormDataEsListVO formDataListVO = saasListService.delClueList(formDataListDTO);
                List<PaasFormDataEntityExt> esEntities = formDataListVO.getPaasFormDataESList();
                Integer totalCount = formDataListVO.getPageHelper().getRowsCount();
                ListAppVO listAppVO = new ListAppVO();
                if (totalCount != null && totalCount != 0) {
                    listAppVO = clueService.formatClueAppList(formDataListDTO, esEntities, totalCount);
                } else {
                    listAppVO.setList(new ArrayList<>());
                    listAppVO.setTotalCount(0);
                }
                listAppVO.setAddPermission(saasListService.getAppListAddPermission(formDataListVO));
                response = new XbbResponse<>(formDataListVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }
        return JSON.toJSONString(response, SerializerFeature.DisableCircularReferenceDetect);
    }

    /**
     * 线索公海池
     * @param formDataListDTO
     * @param br
     * @return
     */
    @RequestMapping(value = "/publicClue", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String publicClue(@RequestBody @Valid FormDataListDTO formDataListDTO, BindingResult br) {
        XbbResponse<ListAppVO> response;
        if (br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                TransmittableThreadLocalUtil.setValue(formDataListDTO.getSaasMark(), formDataListDTO.getBusinessType(), formDataListDTO.getMenuId(), DistributorMarkEnum.OTHER.getCode());
//                PaasFormDataEsListVO formDataListVO = saasListService.publicClue(formDataListDTO);
//                List<PaasFormDataEntityExt> esEntities = formDataListVO.getPaasFormDataESList();
//                esEntities.forEach(item -> {
//                    item.getData().put(ClueEnum.IS_PUBLIC.getAttr(), BasicConstant.ONE);
//                });
//                Integer totalCount = formDataListVO.getPageHelper().getRowsCount();
//                ListAppVO listAppVO = new ListAppVO();
//                if (totalCount != null && totalCount != 0) {
//                    listAppVO = clueService.formatClueAppList(formDataListDTO, esEntities, totalCount);
//                } else {
//                    listAppVO.setList(new ArrayList<>());
//                    listAppVO.setTotalCount(0);
//                }
//                listAppVO.setAddPermission(saasListService.getAppListAddPermission(formDataListVO));
//                listAppVO.setBottomPermissions(formDataListVO.getBottomPermissions());
                ListAppVO listAppVO = dingtalkPublicPoolListQry.publicPoolDinktalkExecute(formDataListDTO);
                response = new XbbResponse<>(listAppVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }
        return JSON.toJSONString(response, SerializerFeature.DisableCircularReferenceDetect);
    }

    /**
     * 获取客户查重列表
     * @param customerCheckRepeatDTO
     * @param br
     * @return
     */
    @RequestMapping(value = "/duplicateCustomer", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String duplicateCustomerList(@RequestBody @Valid CustomerCheckRepeatDTO customerCheckRepeatDTO, BindingResult br) {
        XbbResponse<ListAppVO> response;
        if (br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                TransmittableThreadLocalUtil.setValue(SaasMarkEnum.SAAS.getCode(), XbbRefTypeEnum.CUSTOMER_MANAGEMENT.getCode(), null, customerCheckRepeatDTO.getDistributorMark());
                ListAppVO listAppVO = customerService.formatDuplicateCustomerAppList(customerCheckRepeatDTO);
                List<ListTopButtonEnum> topButtonEnumList = ListTopButtonEnum.getByBusinessType(XbbRefTypeEnum.CUSTOMER_DUPLICATE.getCode());
                List<ButtonPojo> topButtonList = new ArrayList<>();
                for (ListTopButtonEnum topButtonEnum : topButtonEnumList) {
                    ButtonPojo buttonPojo = new ButtonPojo();
                    BeanUtil.copyProperties(topButtonEnum.getAnEnum(), buttonPojo);
                    topButtonList.add(buttonPojo);
                }
                if (Objects.nonNull(topButtonList) && !topButtonList.isEmpty()) {
                    for (ButtonPojo buttonPojo : topButtonList) {
                        if (Objects.nonNull(buttonPojo) && Objects.equals(buttonPojo.getAttr(), SaasButtonEnum.ADD.getAttr())) {
                            listAppVO.setAddPermission(true);
                        }
                    }
                }
                response = new XbbResponse<>(listAppVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }
        return JSON.toJSONString(response, SerializerFeature.DisableCircularReferenceDetect);
    }

    /**
     * 首页获取库存查询列表卡片
     * @param productStockWarningListDTO
     * @param br
     * @return
     */
    @RequestMapping(value = "/productStock/warningListAjax", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String productStockWarningList(@RequestBody @Valid ProductStockWarningListDTO productStockWarningListDTO, BindingResult br) {
        XbbResponse<ProductStockWarningListVO> response;
        if (br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                TransmittableThreadLocalUtil.setValue(SaasMarkEnum.SAAS.getCode(), XbbRefTypeEnum.PRODUCT.getCode(), null, productStockWarningListDTO.getDistributorMark());
                ProductStockWarningListVO formDataListVO = saasListService.productStockWarningList(productStockWarningListDTO);
                response = new XbbResponse<>(formDataListVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }
        return JSON.toJSONString(response, SerializerFeature.DisableCircularReferenceDetect);
    }

    /**
     * 客户公海池
     * @param formDataListDTO
     * @param br
     * @return
     */
    @RequestMapping(value = "/publicCustomer", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String publicCustomer(@RequestBody @Valid FormDataListDTO formDataListDTO, BindingResult br) {
        XbbResponse<ListAppVO> response;
        if (br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                TransmittableThreadLocalUtil.setValue(formDataListDTO.getSaasMark(), formDataListDTO.getBusinessType(), formDataListDTO.getMenuId(), formDataListDTO.getDistributorMark());
//                PaasFormDataEsListVO formDataListVO = saasListService.publicCustomer(formDataListDTO);
//                List<PaasFormDataEntityExt> esEntities = formDataListVO.getPaasFormDataESList();
//                esEntities.forEach(item -> {
//                    item.getData().put(CustomerManagementEnum.IS_PUBLIC.getAttr(), BasicConstant.ONE);
//                });
//                Integer totalCount = formDataListVO.getPageHelper().getRowsCount();
//                ListAppVO listAppVO = new ListAppVO();
//                if (totalCount != null && totalCount != 0) {
//                    listAppVO = customerService.formatCustomerAppList(formDataListDTO, esEntities, totalCount);
//                } else {
//                    listAppVO.setList(new ArrayList<>());
//                    listAppVO.setTotalCount(0);
//                }
//                listAppVO.setAddPermission(saasListService.getAppListAddPermission(formDataListVO));
//                listAppVO.setBottomPermissions(formDataListVO.getBottomPermissions());
                ListAppVO listAppVO = dingtalkPublicPoolListQry.publicPoolDinktalkExecute(formDataListDTO);
                response = new XbbResponse<>(listAppVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }
        return JSON.toJSONString(response, SerializerFeature.DisableCircularReferenceDetect);
    }

    /**
     * 获取附近客户数据列表
     * @param nearCustomerDTO
     * @param br
     * @return
     */
    @RequestMapping(value = "/nearCustomer", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String nearCustomerList(@RequestBody @Valid NearCustomerDTO nearCustomerDTO, BindingResult br) {
        XbbResponse<ListAppVO> response;
        if (br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                TransmittableThreadLocalUtil.setValue(SaasMarkEnum.SAAS.getCode(), XbbRefTypeEnum.CUSTOMER_MANAGEMENT.getCode(), null, nearCustomerDTO.getDistributorMark());
                ListAppVO listAppVO = saasListService.mobileNearCustomerList(nearCustomerDTO);
                if (listAppVO.getList().isEmpty()) {
                    listAppVO.setTotalCount(0);
                }
                List<ListTopButtonEnum> topButtonEnumList = ListTopButtonEnum.getByBusinessType(XbbRefTypeEnum.CUSTOMER_NEARBY.getCode());
                List<ButtonPojo> topButtonList = new ArrayList<>();
                for (ListTopButtonEnum topButtonEnum : topButtonEnumList) {
                    ButtonPojo buttonPojo = new ButtonPojo();
                    BeanUtil.copyProperties(topButtonEnum.getAnEnum(), buttonPojo);
                    topButtonList.add(buttonPojo);
                }
                if (Objects.nonNull(topButtonList) && !topButtonList.isEmpty()) {
                    for (ButtonPojo buttonPojo : topButtonList) {
                        if (Objects.nonNull(buttonPojo) && Objects.equals(buttonPojo.getAttr(), SaasButtonEnum.ADD.getAttr())) {
                            listAppVO.setAddPermission(true);
                        }
                    }
                }
                response = new XbbResponse<>(listAppVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }
        return JSON.toJSONString(response, SerializerFeature.DisableCircularReferenceDetect);
    }

    /**
     * 获取联系人数据列表
     * @param formDataListDTO
     * @param br
     * @return
     */
    @RequestMapping(value = "/contact", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String contactList(@RequestBody @Valid FormDataListDTO formDataListDTO, BindingResult br) {
        XbbResponse<ListAppVO> response;
        if (br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                TransmittableThreadLocalUtil.setValue(formDataListDTO.getSaasMark(), formDataListDTO.getBusinessType(), formDataListDTO.getMenuId(), formDataListDTO.getDistributorMark());
//                PaasFormDataEsListVO paasFormDataEsListVO = saasListService.contactList(formDataListDTO);
//                List<PaasFormDataEntityExt> esEntities = paasFormDataEsListVO.getPaasFormDataESList();
//                Integer totalCount = paasFormDataEsListVO.getPageHelper().getRowsCount();
//                ListAppVO listAppVO = new ListAppVO();
//                if ( totalCount != null && totalCount != 0) {
//                    listAppVO = contactService.formatContactAppList(formDataListDTO, esEntities, totalCount);
//                } else {
//                    listAppVO.setList(new ArrayList<>());
//                    listAppVO.setTotalCount(0);
//                }
//                listAppVO.setAddPermission(saasListService.getAppListAddPermission(paasFormDataEsListVO));
                ListAppVO listAppVO = contactListService.dingtalkList(formDataListDTO);
                response = new XbbResponse<>(listAppVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }
        return JSON.toJSONString(response, SerializerFeature.DisableCircularReferenceDetect);
    }

    /**
     * 获取机会数据列表
     * @param formDataListDTO
     * @param br
     * @return
     */
    @RequestMapping(value = "/opportunity", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String opportunityList(@RequestBody @Valid FormDataListDTO formDataListDTO, BindingResult br) {
        XbbResponse<ListAppVO> response;
        if (br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                TransmittableThreadLocalUtil.setValue(formDataListDTO.getSaasMark(), formDataListDTO.getBusinessType(), formDataListDTO.getMenuId(), formDataListDTO.getDistributorMark());
//                PaasFormDataEsListVO paasFormDataEsListVO = saasListService.opportunityList(formDataListDTO);
//                List<PaasFormDataEntityExt> esEntities = paasFormDataEsListVO.getPaasFormDataESList();
//                Integer totalCount = paasFormDataEsListVO.getPageHelper().getRowsCount();
//                ListAppVO listAppVO = new ListAppVO();
//                if (totalCount != null && totalCount != 0) {
//                    listAppVO = opportunityService.formatOpportunityAppList(formDataListDTO, esEntities, totalCount);
//                } else {
//                    listAppVO.setList(new ArrayList<>());
//                    listAppVO.setTotalCount(0);
//                }
//                listAppVO.setAddPermission(saasListService.getAppListAddPermission(paasFormDataEsListVO));
                ListAppVO listAppVO = opportunityListService.dingtalkList(formDataListDTO);
                response = new XbbResponse<>(listAppVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }
        return JSON.toJSONString(response, SerializerFeature.DisableCircularReferenceDetect);
    }

    /**
     * 获取合同数据列表
     * @param formDataListDTO
     * @param br
     * @return
     */
    @RequestMapping(value = "/contract", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String contractList(@RequestBody @Valid FormDataListDTO formDataListDTO, BindingResult br) {
        XbbResponse<ListAppVO> response;
        if (br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                TransmittableThreadLocalUtil.setValue(formDataListDTO.getSaasMark(), formDataListDTO.getBusinessType(), formDataListDTO.getMenuId(), formDataListDTO.getDistributorMark());
                Integer distributorMark = formDataListDTO.getDistributorMark();
                PaasFormDataEsListVO paasFormDataEsListVO;
                ListAppVO listAppVO = new ListAppVO();
                if (Objects.equals(distributorMark, DistributorMarkEnum.DISTRIBUTOR.getCode())){
                    paasFormDataEsListVO = saasListService.orderList(formDataListDTO);
                    List<PaasFormDataEntityExt> esEntities = paasFormDataEsListVO.getPaasFormDataESList();
                    Integer totalCount = paasFormDataEsListVO.getPageHelper().getRowsCount();

                    if (totalCount != null && totalCount != 0) {
                        listAppVO = orderService.formatOrderAppList(formDataListDTO,esEntities,totalCount);
                    } else {
                        listAppVO.setList(new ArrayList<>());
                        listAppVO.setTotalCount(0);
                    }
                    listAppVO.setAddPermission(saasListService.getAppListAddPermission(paasFormDataEsListVO));
                }else {
                    listAppVO = contractListService.dingtalkList(formDataListDTO);
                }
                response = new XbbResponse<>(listAppVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }
        return JSON.toJSONString(response, SerializerFeature.DisableCircularReferenceDetect);
    }

    /**
     * 获取发票数据列表
     * @param formDataListDTO
     * @param br
     * @return
     */
    @RequestMapping(value = "/invoice", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String invoiceList(@RequestBody @Valid FormDataListDTO formDataListDTO, BindingResult br) {
        XbbResponse<ListAppVO> response;
        if (br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                TransmittableThreadLocalUtil.setValue(formDataListDTO.getSaasMark(), formDataListDTO.getBusinessType(), formDataListDTO.getMenuId(), formDataListDTO.getDistributorMark());
                PaasFormDataEsListVO paasFormDataEsListVO = saasListService.invoiceList(formDataListDTO);
                List<PaasFormDataEntityExt> esEntities = paasFormDataEsListVO.getPaasFormDataESList();
                Integer totalCount = paasFormDataEsListVO.getPageHelper().getRowsCount();
                ListAppVO listAppVO = new ListAppVO();
                if (totalCount != null && totalCount != 0) {
                    listAppVO = invoiceService.formatInvoiceAppList(formDataListDTO, esEntities, totalCount);
                } else {
                    listAppVO.setList(new ArrayList<>());
                    listAppVO.setTotalCount(0);
                }
                listAppVO.setAddPermission(saasListService.getAppListAddPermission(paasFormDataEsListVO));
                response = new XbbResponse<>(listAppVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }
        return JSON.toJSONString(response, SerializerFeature.DisableCircularReferenceDetect);
    }

    /**
     * 获取发票数据列表
     * @param formDataListDTO
     * @param br
     * @return
     */
    @RequestMapping(value = "/purchaseInvoice", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String purchaseInvoiceList(@RequestBody @Valid FormDataListDTO formDataListDTO, BindingResult br) {
        XbbResponse<ListAppVO> response;
        if (br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                TransmittableThreadLocalUtil.setValue(formDataListDTO.getSaasMark(), formDataListDTO.getBusinessType(), formDataListDTO.getMenuId(), formDataListDTO.getDistributorMark());
                PaasFormDataEsListVO paasFormDataEsListVO = saasListService.purchaseInvoiceList(formDataListDTO);
                List<PaasFormDataEntityExt> esEntities = paasFormDataEsListVO.getPaasFormDataESList();
                Integer totalCount = paasFormDataEsListVO.getPageHelper().getRowsCount();
                ListAppVO listAppVO = new ListAppVO();
                if (totalCount != null && totalCount != 0) {
                    listAppVO = purchaseInvoiceService.formatInvoiceAppList(formDataListDTO, esEntities, totalCount);
                } else {
                    listAppVO.setList(new ArrayList<>());
                    listAppVO.setTotalCount(0);
                }
                listAppVO.setAddPermission(saasListService.getAppListAddPermission(paasFormDataEsListVO));
                response = new XbbResponse<>(listAppVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }
        return JSON.toJSONString(response, SerializerFeature.DisableCircularReferenceDetect);
    }

    /**
     * 获取回款数据列表
     * @param formDataListDTO
     * @param br
     * @return
     */
    @RequestMapping(value = "/payment", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String paymentList(@RequestBody @Valid FormDataListDTO formDataListDTO, BindingResult br) {
        XbbResponse<ListAppVO> response;
        if (br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                TransmittableThreadLocalUtil.setValue(formDataListDTO.getSaasMark(), formDataListDTO.getBusinessType(), formDataListDTO.getMenuId(), formDataListDTO.getDistributorMark());
                PaasFormDataEsListVO paasFormDataEsListVO = saasListService.paymentList(formDataListDTO);
                List<PaasFormDataEntityExt> esEntities = paasFormDataEsListVO.getPaasFormDataESList();
                Integer totalCount = paasFormDataEsListVO.getPageHelper().getRowsCount();
                ListAppVO listAppVO = new ListAppVO();
                if (totalCount != null && totalCount != 0) {
                    listAppVO = paymentService.formatPaymentAppList(formDataListDTO, esEntities, totalCount);
                } else {
                    listAppVO.setList(new ArrayList<>());
                    listAppVO.setTotalCount(0);
                }
                listAppVO.setAddPermission(saasListService.getAppListAddPermission(paasFormDataEsListVO));
                response = new XbbResponse<>(listAppVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }
        return JSON.toJSONString(response, SerializerFeature.DisableCircularReferenceDetect);
    }

    /**
     * 获取回款数据列表
     * @param formDataListDTO
     * @param br
     * @return
     */
    @RequestMapping(value = "/prepaymentBalance", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String prepaymentBalanceList(@RequestBody @Valid FormDataListDTO formDataListDTO, BindingResult br) {
        XbbResponse<ListAppVO> response;
        if (br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                TransmittableThreadLocalUtil.setValue(formDataListDTO.getSaasMark(), formDataListDTO.getBusinessType(), formDataListDTO.getMenuId(), formDataListDTO.getDistributorMark());
                ListAppVO listAppVO =  paymentBalanceService.prepaymentBalanceAppList(formDataListDTO);
                response = new XbbResponse<>(listAppVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }
        return JSON.toJSONString(response, SerializerFeature.DisableCircularReferenceDetect);
    }

    /**
     * 回款单列表
     *
     * @param formDataListDTO 入参
     * @param br 错误
     * @return java.lang.String
     * @author 徐俊杰
     * @date 2019/11/20 16:22
     * @since v1.0
     */
    @RequestMapping(value = "/paymentSheet", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String paymentSheetList(@RequestBody @Valid FormDataListDTO formDataListDTO, BindingResult br) {
        XbbResponse<ListAppVO> response;
        if (br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                TransmittableThreadLocalUtil.setValue(formDataListDTO.getSaasMark(), formDataListDTO.getBusinessType(), formDataListDTO.getMenuId(), formDataListDTO.getDistributorMark());
                PaasFormDataEsListVO formDataListVO = saasListService.paymentSheetList(formDataListDTO);
                List<PaasFormDataEntityExt> esEntities = formDataListVO.getPaasFormDataESList();
                Integer totalCount = formDataListVO.getPageHelper().getRowsCount();
                ListAppVO listAppVO = new ListAppVO();
                if (totalCount != null && totalCount != 0) {
                    listAppVO = paymentSheetService.formatPaymentSheetAppList(formDataListDTO, esEntities, totalCount);
                } else {
                    listAppVO.setList(new ArrayList<>());
                    listAppVO.setTotalCount(0);
                }
                listAppVO.setAddPermission(saasListService.getAppListAddPermission(formDataListVO));
                response = new XbbResponse<>(listAppVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }
        return JSON.toJSONString(response, SerializerFeature.DisableCircularReferenceDetect);
    }

    /**
     * 在线支付流水列表
     *
     * @param formDataListDTO 统一列表页入参
     * @param br 错误
     * @return java.lang.String
     * @author zcp
     * @since v1.0
     * @version v1.0
     */
    @RequestMapping(value = "/onlinePaymentFlow", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String onlinePaymentFlow(@RequestBody @Valid FormDataListDTO formDataListDTO, BindingResult br) {
        XbbResponse<ListAppVO> response;
        if (br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                TransmittableThreadLocalUtil.setValue(formDataListDTO.getSaasMark(), formDataListDTO.getBusinessType(), formDataListDTO.getMenuId(), formDataListDTO.getDistributorMark());
                PaasFormDataEsListVO formDataListVO = saasListService.onlinePaymentFlowList(formDataListDTO);
                List<PaasFormDataEntityExt> esEntities = formDataListVO.getPaasFormDataESList();
                Integer totalCount = formDataListVO.getPageHelper().getRowsCount();
                ListAppVO listAppVO = new ListAppVO();
                if (totalCount != null && totalCount != 0) {
                    listAppVO = onlinePaymentFlowService.formatOnlinePaymentFlowAppList(formDataListDTO, esEntities, totalCount);
                } else {
                    listAppVO.setList(new ArrayList<>());
                    listAppVO.setTotalCount(0);
                }
                listAppVO.setAddPermission(false);
                response = new XbbResponse<>(listAppVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }
        return JSON.toJSONString(response, SerializerFeature.DisableCircularReferenceDetect);
    }

    /**
     * 付款单列表
     *
     * @param formDataListDTO 入参
     * @param br 错误
     * @return java.lang.String
     * @author 徐俊杰
     * @date 2020/2/18 15:40
     * @since v1.0
     */
    @RequestMapping(value = "/paySheet", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String paySheetList(@RequestBody @Valid FormDataListDTO formDataListDTO, BindingResult br) {
        XbbResponse<ListAppVO> response;
        if (br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                TransmittableThreadLocalUtil.setValue(formDataListDTO.getSaasMark(), formDataListDTO.getBusinessType(), formDataListDTO.getMenuId(), formDataListDTO.getDistributorMark());
                PaasFormDataEsListVO formDataListVO = saasListService.paySheetList(formDataListDTO);
                List<PaasFormDataEntityExt> esEntities = formDataListVO.getPaasFormDataESList();
                Integer totalCount = formDataListVO.getPageHelper().getRowsCount();
                ListAppVO listAppVO = new ListAppVO();
                if (totalCount != null && totalCount != 0) {
                    listAppVO = payPlanSheetService.formatPaySheetAppList(formDataListDTO, esEntities, totalCount);
                } else {
                    listAppVO.setList(new ArrayList<>());
                    listAppVO.setTotalCount(0);
                }
                listAppVO.setAddPermission(saasListService.getAppListAddPermission(formDataListVO));
                response = new XbbResponse<>(listAppVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }
        return JSON.toJSONString(response, SerializerFeature.DisableCircularReferenceDetect);
    }

    /**
     * 其他收入单列表
     *
     * @param formDataListDTO 入参
     * @param br 错误
     * @return java.lang.String
     * @author zcp
     * @since v1.0
     */
    @RequestMapping(value = "/otherIncome", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String otherIncome(@RequestBody @Valid FormDataListDTO formDataListDTO, BindingResult br) {
        XbbResponse<ListAppVO> response;
        if (br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                TransmittableThreadLocalUtil.setValue(formDataListDTO.getSaasMark(), formDataListDTO.getBusinessType(), formDataListDTO.getMenuId(), formDataListDTO.getDistributorMark());
                PaasFormDataEsListVO formDataListVO = saasListService.otherIncomeList(formDataListDTO);
                List<PaasFormDataEntityExt> esEntities = formDataListVO.getPaasFormDataESList();
                Integer totalCount = formDataListVO.getPageHelper().getRowsCount();
                ListAppVO listAppVO = new ListAppVO();
                if (totalCount != null && totalCount != 0) {
                    listAppVO = otherIncomeService.formatOtherIncomeAppList(formDataListDTO, esEntities, totalCount);
                } else {
                    listAppVO.setList(new ArrayList<>());
                    listAppVO.setTotalCount(0);
                }
                listAppVO.setAddPermission(saasListService.getAppListAddPermission(formDataListVO));
                response = new XbbResponse<>(listAppVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }
        return JSON.toJSONString(response, SerializerFeature.DisableCircularReferenceDetect);
    }
    /**
     * 其他支出单列表
     *
     * @param formDataListDTO 入参
     * @param br 错误
     * @return java.lang.String
     * @author zcp
     * @since v1.0
     */
    @RequestMapping(value = "/otherExpense", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String otherExpense(@RequestBody @Valid FormDataListDTO formDataListDTO, BindingResult br) {
        XbbResponse<ListAppVO> response;
        if (br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                TransmittableThreadLocalUtil.setValue(formDataListDTO.getSaasMark(), formDataListDTO.getBusinessType(), formDataListDTO.getMenuId(), formDataListDTO.getDistributorMark() );
                PaasFormDataEsListVO formDataListVO = saasListService.otherExpenseList(formDataListDTO);
                List<PaasFormDataEntityExt> esEntities = formDataListVO.getPaasFormDataESList();
                Integer totalCount = formDataListVO.getPageHelper().getRowsCount();
                ListAppVO listAppVO = new ListAppVO();
                if (totalCount != null && totalCount != 0) {
                    listAppVO = otherExpenseService.formatOtherExpenseAppList(formDataListDTO, esEntities, totalCount);
                } else {
                    listAppVO.setList(new ArrayList<>());
                    listAppVO.setTotalCount(0);
                }
                listAppVO.setAddPermission(saasListService.getAppListAddPermission(formDataListVO));
                response = new XbbResponse<>(listAppVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }
        return JSON.toJSONString(response, SerializerFeature.DisableCircularReferenceDetect);
    }

    /**
     * 获取工作报告数据列表
     * @param workReportListDTO
     * @param br
     * @return
     */
    @RequestMapping(value = "/workReport", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String workReportList(@RequestBody @Valid WorkReportListDTO workReportListDTO, BindingResult br) {
        XbbResponse<ListAppVO> response;
        if (br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                TransmittableThreadLocalUtil.setValue(workReportListDTO.getSaasMark(), workReportListDTO.getBusinessType(), null, workReportListDTO.getDistributorMark());
                WorkReportVO workReportVO = workReportService.workReportList(workReportListDTO);
                List<WorkReportPojo> esEntities = workReportVO.getList();
                Integer totalCount = workReportVO.getPageHelper().getRowsCount();
                ListAppVO listAppVO = new ListAppVO();
                if (totalCount != null && totalCount != 0) {
                    listAppVO = workReportService.formatWorkReportAppList(workReportListDTO, esEntities, totalCount);
                } else {
                    listAppVO.setList(new ArrayList<>());
                    listAppVO.setTotalCount(0);
                }
                listAppVO.setAddPermission(saasListService.getAppListAddPermission(workReportVO));
                response = new XbbResponse<>(listAppVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }
        return JSON.toJSONString(response, SerializerFeature.DisableCircularReferenceDetect);
    }

    /**
     * 供应商列表
     *
     * @param formDataListDTO 列表筛选条件
     * @author GuoJun.HU
     * @since V1.0
     * @return String
     * @date 2019/3/22 13:46
     */
    @RequestMapping(value = "/supplier", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String supplierList(@RequestBody @Valid FormDataListDTO formDataListDTO, BindingResult br) {
        XbbResponse<ListAppVO> response;
        if (br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                TransmittableThreadLocalUtil.setValue(formDataListDTO.getSaasMark(), formDataListDTO.getBusinessType(), formDataListDTO.getMenuId(), formDataListDTO.getDistributorMark());
                ListAppVO listAppVO= saasListService.appList(formDataListDTO);
                response = new XbbResponse<>(listAppVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }
        return JSON.toJSONString(response, SerializerFeature.DisableCircularReferenceDetect);
    }

    /**
     * 采购合同列表
     *
     * @param formDataListDTO 列表筛选条件
     * @author GuoJun.HU
     * @since V1.0
     * @return String
     * @date 2019/3/22 13:46
     */
    @RequestMapping(value = "/purchase", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String purchaseList(@RequestBody @Valid FormDataListDTO formDataListDTO, BindingResult br) {
        XbbResponse<ListAppVO> response;
        if (br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                TransmittableThreadLocalUtil.setValue(formDataListDTO.getSaasMark(), formDataListDTO.getBusinessType(), formDataListDTO.getMenuId(), formDataListDTO.getDistributorMark());
                ListAppVO listAppVO = saasListService.appList(formDataListDTO);
                response = new XbbResponse<>(listAppVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }
        return JSON.toJSONString(response, SerializerFeature.DisableCircularReferenceDetect);
    }

    /**
     * 获取采购退货数据列表
     *
     * @param formDataListDTO 列表筛选条件
     * @author GuoJun.HU
     * @since V1.0
     * @return String
     * @date 2019/3/22 13:46
     */
    @RequestMapping(value = "/returnedPurchase", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String returnedPurchaseList(@RequestBody @Valid FormDataListDTO formDataListDTO, BindingResult br) {
        XbbResponse<ListAppVO> response;
        if (br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                TransmittableThreadLocalUtil.setValue(formDataListDTO.getSaasMark(), formDataListDTO.getBusinessType(), formDataListDTO.getMenuId(), formDataListDTO.getDistributorMark());
                ListAppVO listAppVO = saasListService.appList(formDataListDTO);
                response = new XbbResponse<>(listAppVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }
        return JSON.toJSONString(response, SerializerFeature.DisableCircularReferenceDetect);
    }

    /**
     * 获取BOM单数据列表
     *
     * @param formDataListDTO 列表筛选条件
     * @author GuoJun.HU
     * @since V1.0
     * @return String
     * @date 2019/3/22 13:46
     */
    @RequestMapping(value = "/bombill", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String bomBillList(@RequestBody @Valid FormDataListDTO formDataListDTO, BindingResult br) {
        XbbResponse<ListAppVO> response;
        if (br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                TransmittableThreadLocalUtil.setValue(formDataListDTO.getSaasMark(), formDataListDTO.getBusinessType(), formDataListDTO.getMenuId(), formDataListDTO.getDistributorMark());
                ListAppVO listAppVO = saasListService.appList(formDataListDTO);
                response = new XbbResponse<>(listAppVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }
        return JSON.toJSONString(response, SerializerFeature.DisableCircularReferenceDetect);
    }

    /**
     * 获取生产单数据列表
     *
     * @param formDataListDTO 列表筛选条件
     * @author GuoJun.HU
     * @since V1.0
     * @return String
     * @date 2019/3/22 13:46
     */
    @RequestMapping(value = "/productionOrder", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String productionOrderList(@RequestBody @Valid FormDataListDTO formDataListDTO, BindingResult br) {
        XbbResponse<ListAppVO> response;
        if (br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                TransmittableThreadLocalUtil.setValue(formDataListDTO.getSaasMark(), formDataListDTO.getBusinessType(), formDataListDTO.getMenuId(), formDataListDTO.getDistributorMark());
                ListAppVO listAppVO = saasListService.appList(formDataListDTO);
                response = new XbbResponse<>(listAppVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }
        return JSON.toJSONString(response, SerializerFeature.DisableCircularReferenceDetect);
    }

    /**
     * 获取装配单数据列表
     *
     * @param formDataListDTO 列表筛选条件
     * @author GuoJun.HU
     * @since V1.0
     * @return String
     * @date 2019/3/22 13:46
     */
    @RequestMapping(value = "/assemble", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String assembleList(@RequestBody @Valid FormDataListDTO formDataListDTO, BindingResult br) {
        XbbResponse<ListAppVO> response;
        if (br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                TransmittableThreadLocalUtil.setValue(formDataListDTO.getSaasMark(), formDataListDTO.getBusinessType(), formDataListDTO.getMenuId(), formDataListDTO.getDistributorMark());
                ListAppVO listAppVO = saasListService.appList(formDataListDTO);
                response = new XbbResponse<>(listAppVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }
        return JSON.toJSONString(response, SerializerFeature.DisableCircularReferenceDetect);
    }

    /**
     * 获取入库单数据列表
     *
     * @param formDataListDTO 列表筛选条件
     * @author GuoJun.HU
     * @since V1.0
     * @return String
     * @date 2019/3/22 13:46
     */
    @RequestMapping(value = "/instock", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String instockList(@RequestBody @Valid FormDataListDTO formDataListDTO, BindingResult br) {
        XbbResponse<ListAppVO> response;
        if (br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                TransmittableThreadLocalUtil.setValue(formDataListDTO.getSaasMark(), formDataListDTO.getBusinessType(), formDataListDTO.getMenuId(), formDataListDTO.getDistributorMark());
                ListAppVO listAppVO = saasListService.appList(formDataListDTO);
                response = new XbbResponse<>(listAppVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }
        return JSON.toJSONString(response, SerializerFeature.DisableCircularReferenceDetect);
    }

    /**
     * 获取出库单数据列表
     *
     * @param formDataListDTO 列表筛选条件
     * @author GuoJun.HU
     * @since V1.0
     * @return String
     * @date 2019/3/22 13:46
     */
    @RequestMapping(value = "/outstock", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String outstockList(@RequestBody @Valid FormDataListDTO formDataListDTO, BindingResult br) {
        XbbResponse<ListAppVO> response;
        if (br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                TransmittableThreadLocalUtil.setValue(formDataListDTO.getSaasMark(), formDataListDTO.getBusinessType(), formDataListDTO.getMenuId(), formDataListDTO.getDistributorMark());
                ListAppVO listAppVO = saasListService.appList(formDataListDTO);
                response = new XbbResponse<>(listAppVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }
        return JSON.toJSONString(response, SerializerFeature.DisableCircularReferenceDetect);
    }

    /**
     * 获取盘点单数据列表
     *
     * @param formDataListDTO 列表筛选条件
     * @author GuoJun.HU
     * @since V1.0
     * @return String
     * @date 2019/3/22 13:46
     */
    @RequestMapping(value = "/inventory", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String inventoryList(@RequestBody @Valid FormDataListDTO formDataListDTO, BindingResult br) {
        XbbResponse<ListAppVO> response;
        if (br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                TransmittableThreadLocalUtil.setValue(formDataListDTO.getSaasMark(), formDataListDTO.getBusinessType(), formDataListDTO.getMenuId(), formDataListDTO.getDistributorMark());
                ListAppVO listAppVO = saasListService.appList(formDataListDTO);
                response = new XbbResponse<>(listAppVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }
        return JSON.toJSONString(response, SerializerFeature.DisableCircularReferenceDetect);
    }

    /**
     * 调拨单列表
     *
     * @param formDataListDTO 统一列表页入参
     * @param br 错误
     * @return java.lang.String
     */
    @RequestMapping(value = "/fundTransfer", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String fundTransferList(@RequestBody @Valid FormDataListDTO formDataListDTO, BindingResult br) {
        XbbResponse<ListAppVO> response;
        if (br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                TransmittableThreadLocalUtil.setValue(formDataListDTO.getSaasMark(), formDataListDTO.getBusinessType(), formDataListDTO.getMenuId(), formDataListDTO.getDistributorMark());
                ListAppVO listAppVO = saasListService.appList(formDataListDTO);
                response = new XbbResponse<>(listAppVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }
        return JSON.toJSONString(response, SerializerFeature.DisableCircularReferenceDetect);
    }


    /**
     * 获取报销单数据列表
     *
     * @param formDataListDTO 列表筛选条件
     * @author chy
     * @since V1.0
     * @return String
     * @date 2019/3/22 13:46
     */
    @RequestMapping(value = "/reimbursementForm", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String reimbursementFormList(@RequestBody @Valid FormDataListDTO formDataListDTO, BindingResult br) {
        XbbResponse<ListAppVO> response;
        if (br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                ListAppVO listAppVO = saasListService.appList(formDataListDTO);
                response = new XbbResponse<>(listAppVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }
        return JSON.toJSONString(response, SerializerFeature.DisableCircularReferenceDetect);
    }

    /**
     * 获取费用数据列表
     *
     * @param formDataListDTO 列表筛选条件
     * @author chy
     * @since V1.0
     * @return String
     * @date 2019/3/22 13:46
     */
    @RequestMapping(value = "/expense", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String rexpenseList(@RequestBody @Valid FormDataListDTO formDataListDTO, BindingResult br) {
        XbbResponse<ListAppVO> response;
        if (br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                ListAppVO listAppVO = saasListService.appList(formDataListDTO);
                response = new XbbResponse<>(listAppVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }
        return JSON.toJSONString(response, SerializerFeature.DisableCircularReferenceDetect);
    }

    /**
     * 获取调拨单数据列表
     *
     * @param formDataListDTO 列表筛选条件
     * @author GuoJun.HU
     * @since V1.0
     * @return String
     * @date 2019/3/22 13:46
     */
    @RequestMapping(value = "/transfer", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String transferList(@RequestBody @Valid FormDataListDTO formDataListDTO, BindingResult br) {
        XbbResponse<ListAppVO> response;
        if (br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                TransmittableThreadLocalUtil.setValue(formDataListDTO.getSaasMark(), formDataListDTO.getBusinessType(), formDataListDTO.getMenuId(), formDataListDTO.getDistributorMark());
                ListAppVO listAppVO = saasListService.appList(formDataListDTO);
                response = new XbbResponse<>(listAppVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }
        return JSON.toJSONString(response, SerializerFeature.DisableCircularReferenceDetect);
    }

    /**
     * 获取付款计划数据列表
     *
     * @param formDataListDTO 列表筛选条件
     * @author GuoJun.HU
     * @since V1.0
     * @return String
     * @date 2019/3/22 13:46
     */
    @RequestMapping(value = "/payPlan", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String payPlanList(@RequestBody @Valid FormDataListDTO formDataListDTO, BindingResult br) {
        XbbResponse<ListAppVO> response;
        if (br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                TransmittableThreadLocalUtil.setValue(formDataListDTO.getSaasMark(), formDataListDTO.getBusinessType(), formDataListDTO.getMenuId(), formDataListDTO.getDistributorMark());
                ListAppVO listAppVO = saasListService.appList(formDataListDTO);
                response = new XbbResponse<>(listAppVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }
        return JSON.toJSONString(response, SerializerFeature.DisableCircularReferenceDetect);
    }

    /**
     * 获取供应商联系人数据列表
     *
     * @param formDataListDTO 列表筛选条件
     * @author GuoJun.HU
     * @since V1.0
     * @return String
     * @date 2019/3/22 13:46
     */
    @RequestMapping(value = "/supplierContact", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String supplierContactList(@RequestBody @Valid FormDataListDTO formDataListDTO, BindingResult br) {
        XbbResponse<ListAppVO> response;
        if (br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                TransmittableThreadLocalUtil.setValue(formDataListDTO.getSaasMark(), formDataListDTO.getBusinessType(), formDataListDTO.getMenuId(), formDataListDTO.getDistributorMark());
                ListAppVO listAppVO = saasListService.appList(formDataListDTO);
                response = new XbbResponse<>(listAppVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }
        return JSON.toJSONString(response, SerializerFeature.DisableCircularReferenceDetect);
    }

    /**
     * 获取仓库数据列表
     *
     * @param formDataListDTO 列表筛选条件
     * @author GuoJun.HU
     * @since V1.0
     * @return String
     * @date 2019/3/22 13:46
     */
    @RequestMapping(value = "/warehouse", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String warehouseList(@RequestBody @Valid FormDataListDTO formDataListDTO, BindingResult br) {
        XbbResponse<ListAppVO> response;
        if (br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                TransmittableThreadLocalUtil.setValue(formDataListDTO.getSaasMark(), formDataListDTO.getBusinessType(), formDataListDTO.getMenuId(), formDataListDTO.getDistributorMark());
                ListAppVO listAppVO = saasListService.appList(formDataListDTO);
                response = new XbbResponse<>(listAppVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }
        return JSON.toJSONString(response, SerializerFeature.DisableCircularReferenceDetect);
    }

    /**
     * 获取产品数据列表
     *
     * @param formDataListDTO 列表筛选条件
     * @author GuoJun.HU
     * @since V1.0
     * @return String
     * @date 2019/3/22 13:46
     */
    @RequestMapping(value = "/product", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String productList(@RequestBody @Valid FormDataListDTO formDataListDTO, BindingResult br) {
        XbbResponse<ListAppVO> response;
        if (br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                TransmittableThreadLocalUtil.setValue(formDataListDTO.getSaasMark(), formDataListDTO.getBusinessType(), formDataListDTO.getMenuId(), formDataListDTO.getDistributorMark());
                ListAppVO listAppVO = saasListService.appList(formDataListDTO);
                response = new XbbResponse<>(listAppVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }
        return JSON.toJSONString(response, SerializerFeature.DisableCircularReferenceDetect);
    }

    /**
     * 获取竞争对手列表
     */
    @RequestMapping(value = "/competitor",method = RequestMethod.POST,produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String competitorList(@RequestBody @Valid FormDataListDTO formDataListDTO,BindingResult br){
        XbbResponse<ListAppVO> response;
        if (br.hasErrors()){
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        }else {
            try {
                TransmittableThreadLocalUtil.setValue(formDataListDTO.getSaasMark(), formDataListDTO.getBusinessType(), formDataListDTO.getMenuId(), formDataListDTO.getDistributorMark());
                ListAppVO listAppVO = competitorListService.dingtalkList(formDataListDTO);
                response = new XbbResponse<>(listAppVO);
            }catch (XbbException e){
                response = new XbbResponse<>(e);
            }
        }
        return JSON.toJSONString(response,SerializerFeature.DisableCircularReferenceDetect);
    }

    /**
     * 获取产品库存查询列表
     *
     * @param formDataListDTO 列表筛选条件
     * @author GuoJun.HU
     * @since V1.0
     * @return String
     * @date 2019/3/22 13:46
     */
    @RequestMapping(value = "/productStock", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String productStockList(@RequestBody @Valid FormDataListDTO formDataListDTO, BindingResult br) {
        XbbResponse<ListAppExtVO> response;
        if (br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                TransmittableThreadLocalUtil.setValue(formDataListDTO.getSaasMark(), formDataListDTO.getBusinessType(), formDataListDTO.getMenuId(), formDataListDTO.getDistributorMark());
                ListAppVO listAppVO = saasListService.appList(formDataListDTO);
                ListAppExtVO listAppExtVO = new ListAppExtVO();
                BeanUtil.copyProperties(listAppVO, listAppExtVO);
                PaasFormEntityExt paasFormEntityExt = paasFormModel.getByBusinessType(XbbRefTypeEnum.INVENTORY.getCode(), formDataListDTO.getCorpid());
                Set<String> permissionSet =  formDataListDTO.getLoginUser().getPermSet();
                boolean hasInventoryAdd = permissionSet.contains(AddProPermissionAliasEnum.INVENTORY_ADD.getAlias());
                boolean isAdminOrBoss = formDataListDTO.getLoginUser().isAdminOrBoss();
                JSONObject inventoryOption = new JSONObject();
                inventoryOption.put("addPermission", isAdminOrBoss || hasInventoryAdd);
                inventoryOption.put("appId", paasFormEntityExt.getAppId());
                inventoryOption.put("menuId", paasFormEntityExt.getMenuId());
                inventoryOption.put("formId", paasFormEntityExt.getId());
                inventoryOption.put("businessType", XbbRefTypeEnum.INVENTORY.getCode());
                listAppExtVO.setExtraOption(inventoryOption);
                response = new XbbResponse<>(listAppExtVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }
        return JSON.toJSONString(response, SerializerFeature.DisableCircularReferenceDetect);
    }

    @RequestMapping(value = "/stockFlowBill", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String stockFlowBillList(@RequestBody @Valid FormDataListDTO formDataListDTO, BindingResult br) {
        XbbResponse<ListAppVO> response;
        if (br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                TransmittableThreadLocalUtil.setValue(formDataListDTO.getSaasMark(), formDataListDTO.getBusinessType(), formDataListDTO.getMenuId(), formDataListDTO.getDistributorMark());
                ListAppVO listAppVO = saasListService.appList(formDataListDTO);
                response = new XbbResponse<>(listAppVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }
        return JSON.toJSONString(response, SerializerFeature.DisableCircularReferenceDetect);
    }

    @RequestMapping(value = "/batchFlowBill", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String batchFlowBillList(@RequestBody @Valid FormDataListDTO formDataListDTO, BindingResult br) {
        XbbResponse<ListAppVO> response;
        if (br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                ListAppVO listAppVO = saasListService.appList(formDataListDTO);
                response = new XbbResponse<>(listAppVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }
        return JSON.toJSONString(response, SerializerFeature.DisableCircularReferenceDetect);
    }

    @RequestMapping(value = "/stockStandingBook", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String stockStandingBookList(@RequestBody @Valid FormDataListDTO formDataListDTO, BindingResult br) {
        XbbResponse<ListAppVO> response;
        if (br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                TransmittableThreadLocalUtil.setValue(formDataListDTO.getSaasMark(), formDataListDTO.getBusinessType(), formDataListDTO.getMenuId(), formDataListDTO.getDistributorMark());
                ListAppVO listAppVO = saasListService.appList(formDataListDTO);
                response = new XbbResponse<>(listAppVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }
        return JSON.toJSONString(response, SerializerFeature.DisableCircularReferenceDetect);
    }

    /**
     * 加入到客户的团队里
     *
     * @param updateMyTeamDTO 列表筛选条件
     * @author long.rao
     * @date 2019-04-01 19:38
     */
    @RequestMapping(value = "/updateMyTeam", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String updateMyTeam(@RequestBody @Valid UpdateMyTeamDTO updateMyTeamDTO, BindingResult br) {
        XbbResponse<BaseVO> response;
        if (br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                BaseVO baseVO = saasDetailTabService.updateMyTeam(updateMyTeamDTO);
                response = new XbbResponse<>(baseVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }
        return JSON.toJSONString(response, SerializerFeature.DisableCircularReferenceDetect);
    }

    /**
     * 获取仓库数据列表(退货退款合同列表)
     * @param formDataListDTO
     * @param br
     * @return
     */
    @RequestMapping(value = "/returnsAndRefunds", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String refundList(@RequestBody @Valid FormDataListDTO formDataListDTO, BindingResult br) {
        XbbResponse<ListAppVO> response;
        if (br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                TransmittableThreadLocalUtil.setValue(formDataListDTO.getSaasMark(), formDataListDTO.getBusinessType(), formDataListDTO.getMenuId(), formDataListDTO.getDistributorMark());
//                PaasFormDataEsListVO paasFormDataEsListVO = saasListService.refundList(formDataListDTO);
//                List<PaasFormDataEntityExt> esEntities = paasFormDataEsListVO.getPaasFormDataESList();
//                Integer totalCount = paasFormDataEsListVO.getPageHelper().getRowsCount();
//                ListAppVO listAppVO = new ListAppVO();
//                if (totalCount != null && totalCount != 0) {
//                    listAppVO = refundService.formatRefundAppList(formDataListDTO, esEntities, totalCount);
//                } else {
//                    listAppVO.setList(new ArrayList<>());
//                    listAppVO.setTotalCount(0);
//                }
//                listAppVO.setAddPermission(saasListService.getAppListAddPermission(paasFormDataEsListVO));
                ListAppVO listAppVO = commonDingtalkListQry.dingtalkExecute(formDataListDTO);
                response = new XbbResponse<>(listAppVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }
        return JSON.toJSONString(response, SerializerFeature.DisableCircularReferenceDetect);
    }

    /**
     * 访客计划列表
     *
     * @param communicatePlanDTO
     * @param br
     * @return
     */
    @RequestMapping(value = "/communicatePlan", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String communicatePlanList(@RequestBody @Valid CommunicatePlanDTO communicatePlanDTO, BindingResult br) {
        XbbResponse<ListAppVO> response;
        if (br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                TransmittableThreadLocalUtil.setValue(communicatePlanDTO.getSaasMark(), communicatePlanDTO.getBusinessType(), null, communicatePlanDTO.getDistributorMark());
                PaasFormDataEsListVO paasFormDataEsListVO = saasListService.communicatePlanList(communicatePlanDTO);
                List<PaasFormDataEntityExt> esEntities = paasFormDataEsListVO.getPaasFormDataESList();
                Integer totalCount = paasFormDataEsListVO.getPageHelper().getRowsCount();
                ListAppVO listAppVO = new ListAppVO();
                if (totalCount != null && totalCount != 0) {
                    listAppVO = communicatePlanService.formatCommunicatePlanAppList(communicatePlanDTO, esEntities, totalCount);
                } else {
                    listAppVO.setList(new ArrayList<>());
                    listAppVO.setTotalCount(0);
                }
                listAppVO.setAddPermission(communicatePlanDTO.getLoginUser().getPermSet().contains(ProPermissionAliasEnum.COMMUNICATE_PLAN_ADD.getAlias()));
                response = new XbbResponse<>(listAppVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }
        return JSON.toJSONString(response, SerializerFeature.DisableCircularReferenceDetect);
    }
    /**
     * 获取访客计划数据列表
     * @param communicatePlanDTO
     * @param br
     * @return
     */
    @RequestMapping(value = "/list", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String customerPlanList(@RequestBody @Valid CommunicatePlanDTO communicatePlanDTO, BindingResult br) {
        XbbResponse<CustomerPlanVO> response;
        if (br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                TransmittableThreadLocalUtil.setValue(communicatePlanDTO.getSaasMark(), communicatePlanDTO.getBusinessType(), null, communicatePlanDTO.getDistributorMark());
                CustomerPlanVO customerPlanVO = communicatePlanService.list(communicatePlanDTO);
                response = new XbbResponse<>(customerPlanVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }

        return JSON.toJSONString(response, SerializerFeature.DisableCircularReferenceDetect);
    }

    /**
     * Description: 工单列表
     * @param formDataListDTO
     * @param br
     * @return java.lang.String
     * @author 魏荣杰
     * @date 2019/5/6 15:48
     * @since v1.0
     */
    @RequestMapping(value = "/workOrder", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String workOrderList(@RequestBody @Valid FormDataListDTO formDataListDTO, BindingResult br) {
        XbbResponse<ListAppVO> response;
        if (br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                TransmittableThreadLocalUtil.setValue(formDataListDTO.getSaasMark(), formDataListDTO.getBusinessType(), formDataListDTO.getMenuId(), formDataListDTO.getDistributorMark());
                WorkOrderDataEsListVO workOrderDataEsListVO = workOrderFormDataService.normalList(formDataListDTO);
                List<WorkOrderEntityExt> workOrderEntityExts = workOrderDataEsListVO.getPaasFormDataESList();
                Integer totalCount = workOrderDataEsListVO.getPageHelper().getRowsCount();
                ListAppVO listAppVO = new ListAppVO();
                if (totalCount != null && totalCount != 0) {
                    listAppVO = workOrderService.formatWorkOrderAppList(formDataListDTO, workOrderEntityExts, totalCount);
                } else {
                    listAppVO.setList(new ArrayList<>());
                    listAppVO.setTotalCount(0);
                }
                listAppVO.setAddPermission(saasListService.getAppListAddPermission(workOrderDataEsListVO));
                response = new XbbResponse<>(listAppVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }
        return JSON.toJSONString(response, SerializerFeature.DisableCircularReferenceDetect);
    }

    /**
     * Description: 待抢单工单列表
     * @param formDataListDTO
     * @param br
     * @return java.lang.String
     * @author 魏荣杰
     * @date 2019/5/6 15:49
     * @since v1.0
     */
    @RequestMapping(value = "/robWorkOrder", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String robWorkOrderList(@RequestBody @Valid FormDataListDTO formDataListDTO, BindingResult br) {
        XbbResponse<ListAppVO> response;
        if (br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                TransmittableThreadLocalUtil.setValue(formDataListDTO.getSaasMark(), formDataListDTO.getBusinessType(), formDataListDTO.getMenuId(), formDataListDTO.getDistributorMark());
                WorkOrderDataEsListVO workOrderDataEsListVO = workOrderFormDataService.robList(formDataListDTO);
                List<WorkOrderEntityExt> workOrderEntityExts = workOrderDataEsListVO.getPaasFormDataESList();
                Integer totalCount = workOrderDataEsListVO.getPageHelper().getRowsCount();
                ListAppVO listAppVO = new ListAppVO();
                if (totalCount != null && totalCount != 0) {
                    listAppVO = workOrderService.formatWorkOrderAppList(formDataListDTO, workOrderEntityExts, totalCount);
                } else {
                    listAppVO.setList(new ArrayList<>());
                    listAppVO.setTotalCount(0);
                }
                listAppVO.setAddPermission(saasListService.getAppListAddPermission(workOrderEntityExts));
                response = new XbbResponse<>(listAppVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }
        return JSON.toJSONString(response, SerializerFeature.DisableCircularReferenceDetect);
    }

    /**
     * Description: 获取待采购数量,
     * ！！！采购数量有性能问题显式已废弃，只返回0，前端已不显示数量
     * @param baseDTO
     * @param br
     * @return
     */
    @RequestMapping(value = "/getWaitPurchaseCount", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String getWaitPurchaseCount(@RequestBody @Valid BaseDTO baseDTO, BindingResult br) {
        XbbResponse<WaitNumVO> response;
        if (br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            WaitNumVO waitNumVO = new WaitNumVO();
            waitNumVO.setBusinessType(XbbRefTypeEnum.WAIT_PURCHASE.getCode());
            if (baseDTO.getLoginUser().isMaxDataPermission() || baseDTO.getLoginUser().getPermSet().contains(ProPermissionAliasEnum.CONTRACT_VIEW.getAlias())){
                waitNumVO.setPermission(true);
            }else {
                waitNumVO.setPermission(false);
            }
            waitNumVO.setTotalCount(0);
            response = new XbbResponse<>(waitNumVO);
        }
        return JSON.toJSONString(response, SerializerFeature.DisableCircularReferenceDetect);
    }

    /**
     * 获取待采购列表
     * @param formDataListDTO
     * @param br
     * @return
     */
    @RequestMapping(value = "/waitPurchase", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String waitPurchaseList(@RequestBody @Valid FormDataListDTO formDataListDTO, BindingResult br) {
        XbbResponse<ListAppVO> response;
        if (br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                FormDataListDTO clonFormDataListDTO = (FormDataListDTO) CloneUtil.deepClone(formDataListDTO);
                TransmittableThreadLocalUtil.setValue(formDataListDTO.getSaasMark(), formDataListDTO.getBusinessType(), formDataListDTO.getMenuId(), formDataListDTO.getDistributorMark());
                PaasFormDataEsListVO formDataListVO = saasListService.waitPurchaseList(formDataListDTO);
                ListAppVO waitPurchaseList = saasListService.getWaitPurchaseList(clonFormDataListDTO, formDataListVO);
                response = new XbbResponse<>(waitPurchaseList);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }
        return JSON.toJSONString(response, SerializerFeature.DisableCircularReferenceDetect);
    }

    /**
     * 获取以销定购列表
     * @param formDataListDTO
     * @param br
     * @return
     */
    @RequestMapping(value = "/smartReplenishment", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String smartReplenishment(@RequestBody @Valid FormDataListDTO formDataListDTO, BindingResult br) {
        XbbResponse<ListAppVO> response;
        if (br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                TransmittableThreadLocalUtil.setValue(formDataListDTO.getSaasMark(), formDataListDTO.getBusinessType(), formDataListDTO.getMenuId(), formDataListDTO.getDistributorMark());
                PaasFormDataEsListVO formDataListVO = saasListService.smartReplenishment(formDataListDTO);
                ListAppVO smartList = saasListService.getMobileSmartReplenishment(formDataListDTO, formDataListVO);
                response = new XbbResponse<>(smartList);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }
        return JSON.toJSONString(response, SerializerFeature.DisableCircularReferenceDetect);
    }


    /**
     * Description: 获取待生产数量
     * @param baseDTO
     * @param br
     * @return
     */
    @RequestMapping(value = "/getWaitProduceCount", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String getWaitProduceCount(@RequestBody @Valid BaseDTO baseDTO, BindingResult br) throws XbbException {
        XbbResponse<WaitNumVO> response;
        if (br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            TransmittableThreadLocalUtil.setValue(SaasMarkEnum.SAAS.getCode(), XbbRefTypeEnum.PRODUCTION_ORDER.getCode(), null, baseDTO.getDistributorMark());
            WaitNumVO waitNumVO = new WaitNumVO();
            waitNumVO.setBusinessType(XbbRefTypeEnum.WAIT_PRODUCE.getCode());
            if (baseDTO.getLoginUser().isMaxDataPermission() || baseDTO.getLoginUser().getPermSet().contains(ProPermissionAliasEnum.CONTRACT_VIEW.getAlias())){
                waitNumVO.setPermission(true);
                Integer count = saasListHelp.getWaitProduceCount(baseDTO.getLoginUser());
                waitNumVO.setTotalCount(count);
            }else {
                waitNumVO.setPermission(false);
                waitNumVO.setTotalCount(0);
            }
            response = new XbbResponse<>(waitNumVO);
        }
        return JSON.toJSONString(response, SerializerFeature.DisableCircularReferenceDetect);
    }

    /**
     * 获取待生产列表
     * @param formDataListDTO
     * @param br
     * @return
     */
    @RequestMapping(value = "/waitProduce", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String waitProduceList(@RequestBody @Valid FormDataListDTO formDataListDTO, BindingResult br) {
        XbbResponse<ListAppVO> response;
        if (br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                TransmittableThreadLocalUtil.setValue(formDataListDTO.getSaasMark(), formDataListDTO.getBusinessType(), formDataListDTO.getMenuId(), formDataListDTO.getDistributorMark());
                PaasFormDataEsListVO formDataListVO = saasListService.waitProduceList(formDataListDTO);
                ListAppVO waitPurchaseList = saasListService.getWaitProduceList(formDataListDTO, formDataListVO);
                response = new XbbResponse<>(waitPurchaseList);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }
        return JSON.toJSONString(response, SerializerFeature.DisableCircularReferenceDetect);
    }

    /**
     * Description: 获取待入库数量
     * @param baseDTO
     * @param br
     * @return
     */
    @RequestMapping(value = "/getWaitInstockCount", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String getWaitInstockCount(@RequestBody @Valid BaseDTO baseDTO, BindingResult br) throws XbbException {
        XbbResponse<WaitNumVO> response;
        if (br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            TransmittableThreadLocalUtil.setValue(SaasMarkEnum.SAAS.getCode(), XbbRefTypeEnum.INSTOCK.getCode(), null, baseDTO.getDistributorMark());
            WaitNumVO waitNumVO = new WaitNumVO();
            waitNumVO.setBusinessType(XbbRefTypeEnum.WAIT_INSTOCK_PURCHASE.getCode());
            if (baseDTO.getLoginUser().isMaxDataPermission() || baseDTO.getLoginUser().getPermSet().contains(ProPermissionAliasEnum.PURCHASE_VIEW.getAlias())){
                waitNumVO.setPermission(true);
                Integer count = saasListHelp.getWaitInstock(baseDTO.getLoginUser());
                waitNumVO.setTotalCount(count);
            }else {
                waitNumVO.setPermission(false);
                waitNumVO.setTotalCount(0);
            }
            response = new XbbResponse<>(waitNumVO);
        }
        return JSON.toJSONString(response, SerializerFeature.DisableCircularReferenceDetect);
    }
    /**
     * 获取视图维度列表
     * @param formDataListDTO
     * @param br
     * @return
     */
    @RequestMapping(value = "/getDimensionViews", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String dimensionViewList(@RequestBody @Valid FormDataListDTO formDataListDTO, BindingResult br) {
        XbbResponse<List<DimensionViewPoJo>> response;
        if (br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                TransmittableThreadLocalUtil.setValue(formDataListDTO.getSaasMark(), formDataListDTO.getBusinessType(), formDataListDTO.getMenuId(), formDataListDTO.getDistributorMark());
                List<DimensionViewPoJo> dimensionViewPoJos = saasListService.dimensionViewList(formDataListDTO);
                response = new XbbResponse<>(dimensionViewPoJos);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }
        return JSON.toJSONString(response, SerializerFeature.DisableCircularReferenceDetect);
    }
    /**
     * 获取待入库列表
     * @param formDataListDTO
     * @param br
     * @return
     */
    @RequestMapping(value = "/waitInstock", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String waitInstockList(@RequestBody @Valid FormDataListDTO formDataListDTO, BindingResult br) {
        XbbResponse<ListAppVO> response;
        if (br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                TransmittableThreadLocalUtil.setValue(formDataListDTO.getSaasMark(), formDataListDTO.getBusinessType(), formDataListDTO.getMenuId(), formDataListDTO.getDistributorMark());
                PaasFormDataEsListVO formDataListVO = saasListService.waitInstockList(formDataListDTO);
                ListAppVO waitInstockList = saasListService.formatWaitContractInstock(formDataListDTO, formDataListVO);
                response = new XbbResponse<>(waitInstockList);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }
        return JSON.toJSONString(response, SerializerFeature.DisableCircularReferenceDetect);
    }

    /**
     * 获取待入库信息详情
     * @param formDataGetDTO
     * @param br
     * @return
     */
    @RequestMapping(value = "/waitInstockDetail", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String waitInstockDetail(@RequestBody @Valid FormDataGetDTO formDataGetDTO, BindingResult br) {
        XbbResponse<ListAppVO> response;
        if (br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                TransmittableThreadLocalUtil.setValue(formDataGetDTO.getSaasMark(), formDataGetDTO.getBusinessType(), formDataGetDTO.getMenuId(), formDataGetDTO.getDistributorMark());
                ListAppVO waitInstockList = saasListService.formatWaitPurchaseInstockDetail(formDataGetDTO);
                response = new XbbResponse<>(waitInstockList);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }
        return JSON.toJSONString(response, SerializerFeature.DisableCircularReferenceDetect);
    }

    /**
     * Description: 获取待出库数量
     * @param baseDTO
     * @param br
     * @return
     */
    @RequestMapping(value = "/getWaitOutstockCount", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String getWaitOutstockCount(@RequestBody @Valid BaseDTO baseDTO, BindingResult br) throws XbbException {
        XbbResponse<WaitNumVO> response;
        if (br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            TransmittableThreadLocalUtil.setValue(SaasMarkEnum.SAAS.getCode(), XbbRefTypeEnum.OUTSTOCK.getCode(), null, baseDTO.getDistributorMark());
            WaitNumVO waitNumVO = new WaitNumVO();
            waitNumVO.setBusinessType(XbbRefTypeEnum.WAIT_OUTSTOCK.getCode());
            if (baseDTO.getLoginUser().isMaxDataPermission() || baseDTO.getLoginUser().getPermSet().contains(ProPermissionAliasEnum.CONTRACT_VIEW.getAlias())){
                waitNumVO.setPermission(true);
                Integer count = saasListHelp.getWaitOutstock(baseDTO.getLoginUser(),baseDTO.getDistributorMark());
                waitNumVO.setTotalCount(count);
            }else {
                waitNumVO.setPermission(false);
                waitNumVO.setTotalCount(0);
            }
            response = new XbbResponse<>(waitNumVO);
        }
        return JSON.toJSONString(response, SerializerFeature.DisableCircularReferenceDetect);
    }

    /**
     * 获取待出库列表
     * @param formDataListDTO
     * @param br
     * @return
     */
    @RequestMapping(value = "/waitOutstock", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String waitOutstockList(@RequestBody @Valid FormDataListDTO formDataListDTO, BindingResult br) {
        XbbResponse<ListAppVO> response = null;
        if (br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                ListAppVO waitOutStockList=new ListAppExtVO();
                TransmittableThreadLocalUtil.setValue(formDataListDTO.getSaasMark(), formDataListDTO.getBusinessType(), formDataListDTO.getMenuId(), formDataListDTO.getDistributorMark());
                //合同维度
                if (Objects.equals(formDataListDTO.getBusinessType(),XbbRefTypeEnum.CONTRACT.getCode())){
                PaasFormDataEsListVO formDataListVO = saasListService.waitOutstockList(formDataListDTO);
                waitOutStockList = saasListService.formatWaitContractOutstock(formDataListDTO, formDataListVO);
                response = new XbbResponse<>(waitOutStockList);
                //产品维度
                }else if (Objects.equals(formDataListDTO.getBusinessType(),XbbRefTypeEnum.PRODUCT.getCode())){
                    waitOutStockList = contractService.formatWaitPrductOutstock(formDataListDTO);
                    response = new XbbResponse<>(waitOutStockList);
                }
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }
        return JSON.toJSONString(response, SerializerFeature.DisableCircularReferenceDetect);
    }

    /**
     * 获取待出库列表--穿透详情
     * @param formDataGetDTO
     * @param br
     * @return
     */
    @RequestMapping(value = "/waitOutstockDetail", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String waitOutstockDetail(@RequestBody @Valid FormDataGetDTO formDataGetDTO, BindingResult br) {
        XbbResponse<ListAppVO> response = null;
        if (br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                TransmittableThreadLocalUtil.setValue(formDataGetDTO.getSaasMark(), formDataGetDTO.getBusinessType(), formDataGetDTO.getMenuId(), formDataGetDTO.getDistributorMark());
                ListAppVO waitInstockList = saasListService.formatWaitContractOutstockDetail(formDataGetDTO);
                response = new XbbResponse<>(waitInstockList);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }
        return JSON.toJSONString(response, SerializerFeature.DisableCircularReferenceDetect);
    }

    /**
     * @Author: wujian
     * @Description: 获取待采购产品详情
     * @Date: 下午4:04 2021/9/13
     * @Param: [formDataListDTO, br]
     * @return: java.lang.String
     **/
    @RequestMapping(value = "/getWaitPurchaseProductDetail", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String getWaitPurchaseProductDetail(@RequestBody @Valid DetailTabDataGetDTO detailTabDataGetDTO, BindingResult br) {
        XbbResponse<WaitPurchaseProductVO> response;
        if (br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                WaitPurchaseProductVO waitPurchaseProductVO = saasListService.getWaitPurchaseProductDetail(detailTabDataGetDTO);
                response = new XbbResponse<>(waitPurchaseProductVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }
        return JSON.toJSONString(response, SerializerFeature.DisableCircularReferenceDetect);
    }

    /**
     * @Author: wujian
     * @Description: 获取以销定购明细
     * @Date: 下午4:04 2021/9/13
     * @Param: [formDataListDTO, br]
     * @return: java.lang.String
     **/
    @RequestMapping(value = "/getorderOnPinDetail", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String getorderOnPinDetail(@RequestBody @Valid OrderOnPinDTO orderOnPinDTO, BindingResult br) {
        XbbResponse<WaitPurchaseDetailVO> response;
        if (br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                WaitPurchaseDetailVO waitPurchaseDetailVO = saasListService.getorderOnPinDetail(orderOnPinDTO);
                response = new XbbResponse<>(waitPurchaseDetailVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }
        return JSON.toJSONString(response, SerializerFeature.DisableCircularReferenceDetect);
    }
    /**
     * 报价单列表
     * @param formDataListDTO
     * @param br
     * @return
     */
    @RequestMapping(value = "/quotation", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String quotationList(@RequestBody @Valid FormDataListDTO formDataListDTO, BindingResult br) {
        XbbResponse<ListAppVO> response;
        if (br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                TransmittableThreadLocalUtil.setValue(formDataListDTO.getSaasMark(), formDataListDTO.getBusinessType(), formDataListDTO.getMenuId(), formDataListDTO.getDistributorMark());
                ListAppVO listAppVO = commonDingtalkListQry.dingtalkExecute(formDataListDTO);
                response = new XbbResponse<>(listAppVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }
        return JSON.toJSONString(response, SerializerFeature.DisableCircularReferenceDetect);
    }

    /**
     * 预付款列表（app）
     *
     * @param formDataListDTO 列表页统一入参
     * @param br 错误
     * @return java.lang.String
     * @author 徐俊杰
     * @date 2020/2/26 11:03
     * @since v1.0
     */
    @RequestMapping(value = "/prepayBalance", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String prepayBalanceList(@RequestBody @Valid FormDataListDTO formDataListDTO, BindingResult br) {
        XbbResponse<ListAppVO> response;
        if (br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                TransmittableThreadLocalUtil.setValue(formDataListDTO.getSaasMark(), formDataListDTO.getBusinessType(), formDataListDTO.getMenuId(), formDataListDTO.getDistributorMark());
                ListAppVO listAppVO =  payBalanceService.prepayBalanceAppList(formDataListDTO);
                response = new XbbResponse<>(listAppVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }
        return JSON.toJSONString(response, SerializerFeature.DisableCircularReferenceDetect);
    }

    /**
     * 获取信用额度数据列表
     * @param formDataListDTO
     * @param br
     * @return
     * @author xingxing.xiao
     */
    @RequestMapping(value = "/creditLimit", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String creditLimitList(@RequestBody @Valid FormDataListDTO formDataListDTO, BindingResult br) {
        XbbResponse<ListAppVO> response;
        if (br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                TransmittableThreadLocalUtil.setValue(formDataListDTO.getSaasMark(), formDataListDTO.getBusinessType(), formDataListDTO.getMenuId(), formDataListDTO.getDistributorMark());
                PaasFormDataEsListVO paasFormDataEsListVO = saasListService.creditLimitList(formDataListDTO);
                List<PaasFormDataEntityExt> esEntities = paasFormDataEsListVO.getPaasFormDataESList();
                Integer totalCount = paasFormDataEsListVO.getPageHelper().getRowsCount();
                ListAppVO listAppVO = new ListAppVO();
                if ( totalCount != null && totalCount != 0) {
                    listAppVO = creditLimitService.formatCreditAppList(formDataListDTO, esEntities, totalCount);
                } else {
                    listAppVO.setList(new ArrayList<>());
                    listAppVO.setTotalCount(0);
                }
                listAppVO.setAddPermission(saasListService.getAppListAddPermission(paasFormDataEsListVO));
                response = new XbbResponse<>(listAppVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }
        return JSON.toJSONString(response, SerializerFeature.DisableCircularReferenceDetect);
    }

    /**
     * 获取临时额度数据列表
     * @param formDataListDTO
     * @param br
     * @return
     * @author xingxing.xiao
     */
    @RequestMapping(value = "/creditTemporaryLimit", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String creditTemporaryLimitList(@RequestBody @Valid FormDataListDTO formDataListDTO, BindingResult br) {
        XbbResponse<ListAppVO> response;
        if (br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                TransmittableThreadLocalUtil.setValue(formDataListDTO.getSaasMark(), formDataListDTO.getBusinessType(), formDataListDTO.getMenuId(), formDataListDTO.getDistributorMark());
                PaasFormDataEsListVO paasFormDataEsListVO = saasListService.creditTemporaryLimitList(formDataListDTO);
                List<PaasFormDataEntityExt> esEntities = paasFormDataEsListVO.getPaasFormDataESList();
                Integer totalCount = paasFormDataEsListVO.getPageHelper().getRowsCount();
                ListAppVO listAppVO = new ListAppVO();
                if ( totalCount != null && totalCount != 0) {
                    listAppVO = creditTemporaryLimitService.formatCreditTemporaryAppList(formDataListDTO, esEntities, totalCount);
                } else {
                    listAppVO.setList(new ArrayList<>());
                    listAppVO.setTotalCount(0);
                }
                listAppVO.setAddPermission(saasListService.getAppListAddPermission(paasFormDataEsListVO));
                response = new XbbResponse<>(listAppVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }
        return JSON.toJSONString(response, SerializerFeature.DisableCircularReferenceDetect);
    }

    /**
     * 获取固定额度数据列表
     * @param formDataListDTO
     * @param br
     * @return
     * @author xingxing.xiao
     */
    @RequestMapping(value = "/creditFixedLimit", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String creditFixedLimitList(@RequestBody @Valid FormDataListDTO formDataListDTO, BindingResult br) {
        XbbResponse<ListAppVO> response;
        if (br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                TransmittableThreadLocalUtil.setValue(formDataListDTO.getSaasMark(), formDataListDTO.getBusinessType(), formDataListDTO.getMenuId(), formDataListDTO.getDistributorMark());
                PaasFormDataEsListVO paasFormDataEsListVO = saasListService.creditFixedLimitList(formDataListDTO);
                List<PaasFormDataEntityExt> esEntities = paasFormDataEsListVO.getPaasFormDataESList();
                Integer totalCount = paasFormDataEsListVO.getPageHelper().getRowsCount();
                ListAppVO listAppVO = new ListAppVO();
                if ( totalCount != null && totalCount != 0) {
                    listAppVO = creditFixedLimitService.formatCreditFixedAppList(formDataListDTO, esEntities, totalCount);
                } else {
                    listAppVO.setList(new ArrayList<>());
                    listAppVO.setTotalCount(0);
                }
                listAppVO.setAddPermission(saasListService.getAppListAddPermission(paasFormDataEsListVO));
                response = new XbbResponse<>(listAppVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }
        return JSON.toJSONString(response, SerializerFeature.DisableCircularReferenceDetect);
    }

    /**
     * 回款计划列表
     *
     * @param paymentTaskGetDTO
     * @param br
     * @return
     */
    @RequestMapping(value = "/paymentTask", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String paymentTaskList(@RequestBody @Valid PaymentTaskGetDTO paymentTaskGetDTO, BindingResult br) {
        XbbResponse<ListAppVO> response;
        if (br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                TransmittableThreadLocalUtil.setValue(paymentTaskGetDTO.getSaasMark(), paymentTaskGetDTO.getBusinessType(), null, paymentTaskGetDTO.getDistributorMark());
                PaasFormDataEsListVO paasFormDataEsListVO = saasListService.paymentTaskList(paymentTaskGetDTO);
                List<PaasFormDataEntityExt> esEntities = paasFormDataEsListVO.getPaasFormDataESList();
                Integer totalCount = paasFormDataEsListVO.getPageHelper().getRowsCount();
                ListAppVO listAppVO = new ListAppVO();
                if (totalCount != null && totalCount != 0) {
                    listAppVO = paymentTaskService.formatPaymentTaskAppList(paymentTaskGetDTO, esEntities, totalCount);
                } else {
                    listAppVO.setList(new ArrayList<>());
                    listAppVO.setTotalCount(0);
                }
                listAppVO.setAddPermission(paymentTaskGetDTO.getLoginUser().getPermSet().contains(ProPermissionAliasEnum.PAYMENT_TASK_ADD.getAlias()));
                response = new XbbResponse<>(listAppVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }
        return JSON.toJSONString(response, SerializerFeature.DisableCircularReferenceDetect);
    }


    /**
     * 获取产品序列号
     * @param formDataListDTO
     * @param br
     * @return
     */
    @RequestMapping(value = "/productSerialList", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String productSerialList(@RequestBody @Valid FormDataListDTO formDataListDTO, BindingResult br) {
        XbbResponse<ListAppVO> response;
        if (br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                ListAppVO listAppVO = saasListService.appList(formDataListDTO);
                response = new XbbResponse<>(listAppVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }
        return JSON.toJSONString(response, SerializerFeature.DisableCircularReferenceDetect);
    }

    @RequestMapping(value = "/marketActivity", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String marketActivityList(@RequestBody @Valid FormDataListDTO formDataListDTO, BindingResult br) {
        XbbResponse<ListAppVO> response;
        if (br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                TransmittableThreadLocalUtil.setValue(formDataListDTO.getSaasMark(), formDataListDTO.getBusinessType(), formDataListDTO.getMenuId(), DistributorMarkEnum.OTHER.getCode());
//                PaasFormDataEsListVO paasFormDataEsListVO = saasListService.marketActivityList(formDataListDTO);
//                List<PaasFormDataEntityExt> esEntities = paasFormDataEsListVO.getPaasFormDataESList();
//                Integer totalCount = paasFormDataEsListVO.getPageHelper().getRowsCount();
//                ListAppVO listAppVO = new ListAppVO();
//                if (totalCount != null && totalCount != 0) {
//                    listAppVO = marketActivityService.formatMarketActivityAppList(formDataListDTO, esEntities, totalCount);
//                } else {
//                    listAppVO.setList(new ArrayList<>());
//                    listAppVO.setTotalCount(0);
//                }
//                listAppVO.setAddPermission(saasListService.getAppListAddPermission(paasFormDataEsListVO));
                ListAppVO listAppVO = marketActivityListService.dingtalkList(formDataListDTO);
                response = new XbbResponse<>(listAppVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }
        return JSON.toJSONString(response, SerializerFeature.DisableCircularReferenceDetect);
    }

    /**
     * 移动端详情页穿  市场活动关联销售线索 列表
     *
     * @param RelationSaleClueListDTO
     * @param br
     * @throws
     * @author long.rao
     * @date 2019-05-29 14:47
     */
    @RequestMapping(value = "/relationSaleClueList", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String getAppRelationSaleClueList(@RequestBody @Valid RelationSaleClueListDTO RelationSaleClueListDTO, BindingResult br) {
        XbbResponse<RelationSaleClueListVO> response;
        if (br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                RelationSaleClueListVO relationSaleClueListVO = mobileDetailService.getAppRelationSaleClueList(RelationSaleClueListDTO);
                response = new XbbResponse<>(relationSaleClueListVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }
        return JSON.toJSONString(response, SerializerFeature.DisableCircularReferenceDetect);
    }

    /**
     * 获取营销活动列表
     * @param formDataListDTO
     * @param br
     * @return
     */
    @RequestMapping(value = "/marketingActivity", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String marketingActivity(@RequestBody @Valid FormDataListDTO formDataListDTO, BindingResult br) {
        XbbResponse<ListAppVO> response;
        if (br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                ListAppVO listAppVO = saasListService.appList(formDataListDTO);
                response = new XbbResponse<>(listAppVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }
        return JSON.toJSONString(response, SerializerFeature.DisableCircularReferenceDetect);
    }

    /**
     * 获取营销活动列表
     * @param formDataListDTO
     * @param br
     * @return
     */
    @RequestMapping(value = "/promotionActivity", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String promotionActivity(@RequestBody @Valid FormDataListDTO formDataListDTO, BindingResult br) {
        XbbResponse<ListAppVO> response;
        if (br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                ListAppVO listAppVO = saasListService.appList(formDataListDTO);
                response = new XbbResponse<>(listAppVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }
        return JSON.toJSONString(response, SerializerFeature.DisableCircularReferenceDetect);
    }

    /**
     * 获取经销商数据列表
     * @param formDataListDTO
     * @param br
     * @return
     */
    @RequestMapping(value = "/distributor", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String distributorList(@RequestBody @Valid FormDataListDTO formDataListDTO, BindingResult br) {
        XbbResponse<ListAppVO> response;
        if (br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                TransmittableThreadLocalUtil.setValue(formDataListDTO.getSaasMark(), formDataListDTO.getBusinessType(), formDataListDTO.getMenuId(), formDataListDTO.getDistributorMark());
                PaasFormDataEsListVO paasFormDataEsListVO = saasListService.distributorList(formDataListDTO);
                List<PaasFormDataEntityExt> esEntities = paasFormDataEsListVO.getPaasFormDataESList();
                Integer totalCount = paasFormDataEsListVO.getPageHelper().getRowsCount();
                ListAppVO listAppVO = new ListAppVO();
                if (totalCount != null && totalCount != 0) {
                    listAppVO = distributorManageService.formatDistributorAppList(formDataListDTO, esEntities, totalCount);
                } else {
                    listAppVO.setList(new ArrayList<>());
                    listAppVO.setTotalCount(0);
                }
                listAppVO.setAddPermission(saasListService.getAppListAddPermission(paasFormDataEsListVO));
                response = new XbbResponse<>(listAppVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }
        return JSON.toJSONString(response, SerializerFeature.DisableCircularReferenceDetect);
    }

    /**
     * 获取经销商地图
     * @param formDataListDTO
     * @param br
     * @return
     */
    @RequestMapping(value = "/distributorMap", method = RequestMethod.POST)
    public String distributorMap(@RequestBody @Valid FormDataListDTO formDataListDTO, BindingResult br) {
        XbbResponse<PaasFormDataEsListVO> response;
        if (br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                TransmittableThreadLocalUtil.setValue(formDataListDTO.getSaasMark(), formDataListDTO.getBusinessType(), formDataListDTO.getMenuId(), formDataListDTO.getDistributorMark());
                formDataListDTO.setIsDistributorMap(1);
                PaasFormDataEsListVO formDataListVO = saasListService.distributorList(formDataListDTO);
                response = new XbbResponse<>(formDataListVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }
        return JSON.toJSONString(response, SerializerFeature.DisableCircularReferenceDetect);
    }

    /**
     * 获取经销商联系人数据列表
     * @param formDataListDTO
     * @param br
     * @return
     */
    @RequestMapping(value = "/distributorContact", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String distributorContactList(@RequestBody @Valid FormDataListDTO formDataListDTO, BindingResult br) {
        XbbResponse<ListAppVO> response;
        if (br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                TransmittableThreadLocalUtil.setValue(formDataListDTO.getSaasMark(), formDataListDTO.getBusinessType(), formDataListDTO.getMenuId(), formDataListDTO.getDistributorMark());
                PaasFormDataEsListVO paasFormDataEsListVO = saasListService.distributorContactList(formDataListDTO);
                List<PaasFormDataEntityExt> esEntities = paasFormDataEsListVO.getPaasFormDataESList();
                Integer totalCount = paasFormDataEsListVO.getPageHelper().getRowsCount();
                ListAppVO listAppVO = new ListAppVO();
                if ( totalCount != null && totalCount != 0) {
                    listAppVO = distributorContactService.formatContactAppList(formDataListDTO, esEntities, totalCount);
                } else {
                    listAppVO.setList(new ArrayList<>());
                    listAppVO.setTotalCount(0);
                }
                listAppVO.setAddPermission(saasListService.getAppListAddPermission(paasFormDataEsListVO));
                response = new XbbResponse<>(listAppVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }
        return JSON.toJSONString(response, SerializerFeature.DisableCircularReferenceDetect);
    }

    /**
     * 获取经销商账号数据列表
     * @param formDataListDTO
     * @param br
     * @return
     */
    @RequestMapping(value = "/distributorAccount", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String distributorAccountList(@RequestBody @Valid FormDataListDTO formDataListDTO, BindingResult br) {
        XbbResponse<ListAppVO> response;
        if (br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                TransmittableThreadLocalUtil.setValue(formDataListDTO.getSaasMark(), formDataListDTO.getBusinessType(), formDataListDTO.getMenuId(), formDataListDTO.getDistributorMark());
                PaasFormDataEsListVO paasFormDataEsListVO = saasListService.distributorAccountList(formDataListDTO);
                List<PaasFormDataEntityExt> esEntities = paasFormDataEsListVO.getPaasFormDataESList();
                Integer totalCount = paasFormDataEsListVO.getPageHelper().getRowsCount();
                ListAppVO listAppVO = new ListAppVO();
                if ( totalCount != null && totalCount != 0) {
                    listAppVO = distributorAccountService.formatAccountAppList(formDataListDTO, esEntities, totalCount);
                } else {
                    listAppVO.setList(new ArrayList<>());
                    listAppVO.setTotalCount(0);
                }
                listAppVO.setAddPermission(saasListService.getAppListAddPermission(paasFormDataEsListVO));
                response = new XbbResponse<>(listAppVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }
        return JSON.toJSONString(response, SerializerFeature.DisableCircularReferenceDetect);
    }


    /**
     * 对账单列表
     * @param formDataListDTO
     * @param br
     * @return
     */
    @RequestMapping(value = "/statement", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String statement(@RequestBody @Valid FormDataListDTO formDataListDTO, BindingResult br) {
        XbbResponse<ListAppVO> response;
        if (br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                TransmittableThreadLocalUtil.setValue(formDataListDTO.getSaasMark(), formDataListDTO.getBusinessType(), formDataListDTO.getMenuId(), formDataListDTO.getDistributorMark());
                ListAppVO listAppVO = saasListService.appList(formDataListDTO);
                response = new XbbResponse<>(listAppVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }
        return JSON.toJSONString(response, SerializerFeature.DisableCircularReferenceDetect);
    }

    /**
     * 经销商跟进记录列表
     * @param formDataListDTO
     * @param br
     * @return
     */
    @RequestMapping(value = "/distributorCommunicate", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String distributorCommunicateList(@RequestBody @Valid FormDataListDTO formDataListDTO, BindingResult br) {
        XbbResponse<CommunicateVO> response;
        if (br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                TransmittableThreadLocalUtil.setValue(formDataListDTO.getSaasMark(), formDataListDTO.getBusinessType(), formDataListDTO.getMenuId(), formDataListDTO.getDistributorMark());
                CommunicateVO communicateVO = distributorCommunicateService.list(formDataListDTO);
                response = new XbbResponse<>(communicateVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }

        return JSON.toJSONString(response, SerializerFeature.DisableCircularReferenceDetect);
    }

    /**
     * 获取产品价目列表
     * @param formDataListDTO
     * @param br
     * @return
     */
    @RequestMapping(value = "/productPriceList", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String productPriceList(@RequestBody @Valid FormDataListDTO formDataListDTO, BindingResult br) {
        XbbResponse<ListAppVO> response;
        if (br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                ListAppVO listAppVO = saasListService.appList(formDataListDTO);
                response = new XbbResponse<>(listAppVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }
        return JSON.toJSONString(response, SerializerFeature.DisableCircularReferenceDetect);
    }

    /**
     * 获取成本调整单数据列表
     *
     * @param formDataListDTO 列表筛选条件
     * @param br              br
     * @return 成本调整单数据列表
     */
    @RequestMapping(value = "/costAdjust", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String costAdjust(@RequestBody @Valid FormDataListDTO formDataListDTO, BindingResult br) {
        XbbResponse<ListAppVO> response;
        if (br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                TransmittableThreadLocalUtil.setValue(formDataListDTO.getSaasMark(), formDataListDTO.getBusinessType(), formDataListDTO.getMenuId(), formDataListDTO.getDistributorMark());
                ListAppVO listAppVO = saasListService.appList(formDataListDTO);
                response = new XbbResponse<>(listAppVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }
        return JSON.toJSONString(response, SerializerFeature.DisableCircularReferenceDetect);
    }


    /**
     * 获取移动端公海分组的筛选条件列表
     */
    @RequestMapping(value = "/screenPublicGroup", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String screenPublicGroup(@RequestBody @Valid GroupApplyScoreGetDTO applyScoreGetDTO, BindingResult br) {
        XbbResponse<PublicGroupScreenVO> response;
        if (br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                PublicGroupSeniorListVO groupSeniorListVO = transferBackRuleSeniorService.applyScoreGet(applyScoreGetDTO);
                PublicGroupScreenVO publicGroupScreenVO = new PublicGroupScreenVO();
                publicGroupScreenVO.setDepartmentTree(groupSeniorListVO.getGroupTree());
                response = new XbbResponse<>(publicGroupScreenVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }
        return JSON.toJSONString(response);
    }

    /**
     * @Author mingliang
     * @Description 知识库列表查询
     * @Date 2022/6/22 19:04
     * @param baseDTO
     * @param br
     **/
    @RequestMapping(value = "/knowledgeBase", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String knowledgeBaseList(@RequestBody @Valid BaseDTO baseDTO, BindingResult br) throws Exception {
        XbbResponse<KnowledgeBaseListVO> response;
        if (br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                KnowledgeBaseListVO knowledgeBaseListVO = knowledgeBaseService.knowledgeBaseList(baseDTO);
                response = new XbbResponse<>(knowledgeBaseListVO);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }
        return JSON.toJSONString(response, SerializerFeature.DisableCircularReferenceDetect);
    }

    /**
     * 获取知识条目列表
     * @Author ruansicheng
     * @param knowledgeListDTO
     * @param br
     * @return
     */
    @RequestMapping(value = "/knowledgeData", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public String knowledgeDataList(@RequestBody @Valid KnowledgeListDTO knowledgeListDTO, BindingResult br) {
        XbbResponse<ListAppVO> response = null;
        if (br.hasErrors()) {
            String errMsg = Objects.requireNonNull(br.getFieldError()).getDefaultMessage();
            response = new XbbResponse<>(SystemErrorCodeEnum.API_ERROR_100002, errMsg);
        } else {
            try {
                ListAppVO knowledgeDataList = new ListAppExtVO();
                TransmittableThreadLocalUtil.setValue(knowledgeListDTO.getSaasMark(), knowledgeListDTO.getBusinessType(), knowledgeListDTO.getMenuId(), knowledgeListDTO.getDistributorMark());
                knowledgeDataList = knowledgeDataService.appKnowledgeDataList(knowledgeListDTO);
                response = new XbbResponse<>(knowledgeDataList);
            } catch (XbbException e) {
                response = new XbbResponse<>(e);
            }
        }
        return JSON.toJSONString(response, SerializerFeature.DisableCircularReferenceDetect);
    }
}
